﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using Nova_DAL;
using System.Data.Common;
using Nova_Common;
using System.Text;
using System.Data;

public partial class Command_CancelCommand : System.Web.UI.Page
{
    string strSQL = "";
    DbHelper access = new DbHelper();
    DbCommand cmd = null;
    int iFlag = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            gv_Bind();
        }
    }

    protected void gv_Bind()
    {
        try
        {
            strSQL = @"SELECT C.TaskID AS TaskID
                            ,C.TaskMode AS TaskMode
                            ,T.Tray_ID AS Tray_ID
                            ,C.TaskStatus AS TaskStatus
                            ,H.UpdateType AS UpdateType
                            ,C.PosS_ID AS PosS_ID
                            ,C.PosE_ID AS PosE_ID
                     FROM
                             TCommands AS C
                            ,TCMDHistory AS H
                            ,TBase_TrayPos AS T
                     WHERE
                             C.TaskID=H.TaskID
                         AND H.Relations_ID =T.Relations_ID";

            cmd = access.GetSqlStringCommond(strSQL);
            gv.DataSource = access.ExecuteDataSet(cmd);
            gv.DataBind();
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }

    protected void ibtnReset_Click(object sender, ImageClickEventArgs e)
    {
        gv_Bind();
    }

    protected void ibtnCancel_Click(object sender, ImageClickEventArgs e)
    {
        HttpCookie cookies = Request.Cookies["UserName"];
        string strTaskID = "";
        try
        {
            for (int i = 0; i < gv.Rows.Count; i++)
            {
                CheckBox chkSelect = (CheckBox)gv.Rows[i].FindControl("chkSelect");
                if (chkSelect.Checked)
                {
                    strTaskID = gv.DataKeys[gv.Rows[i].RowIndex].Value.ToString();
                }
            }

            if (strTaskID == "")
            {
                labErrMsg.Text = "请选择指令号！";
            }
            else
            {
                strSQL = @"execute [SP_Update_CMDs] @TaskID,@XTYPE,@HType,@UserName,@Res output,@ErrMsg output";
                cmd = access.GetSqlStringCommond(strSQL);
                access.AddInParameter(cmd, "@TaskID", DbType.Int32, strTaskID);
                access.AddInParameter(cmd, "@XTYPE", DbType.Int32, 2);//1:强制过账2:撤销过账
                access.AddInParameter(cmd, "@HType", DbType.Int32, 2);
                access.AddInParameter(cmd, "@UserName", DbType.String, cookies.Value);
                access.AddOutParameter(cmd, "@ResNO", DbType.String, 10);
                access.AddOutParameter(cmd, "@ErrMsg", DbType.String, 1000);
                iFlag = access.ExecuteNonQuery(cmd);

                if (iFlag < 0)
                {
                    labErrMsg.Text = access.GetParameter(cmd, "@ErrMsg").Value.ToString();
                }
                else
                {
                    labErrMsg.Text = "操作成功";
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
}
